package org.csu.demo.controller.front;

import org.csu.demo.common.CommonResponse;
import org.csu.demo.entity.Category;
import org.csu.demo.entity.Product;
import org.csu.demo.service.CatalogService;
import org.csu.demo.vo.ItemVO;
import org.omg.CORBA.PUBLIC_MEMBER;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/catalog")
public class CatalogController {

    @Autowired
    private CatalogService catalogService;

    @RequestMapping("/categories")
    @ResponseBody
    public CommonResponse<List<Category>> getCategoryList(){
        return catalogService.getCategoryList();
    }

    @RequestMapping("/categories/{id}")
    @ResponseBody
    public CommonResponse<Category> getCategory(@PathVariable("id") String categoryId){
        return catalogService.getCategory(categoryId);
    }

    @RequestMapping("/categories/{id}/products")
    @ResponseBody
    public CommonResponse<List<Product>> getProductList(@PathVariable("id") String categoryId){
        return catalogService.getProductList(categoryId);
    }

    @RequestMapping("/products/{id}")
    @ResponseBody
    public CommonResponse<Product> getProduct(@PathVariable("id") String productId){
        return catalogService.getProduct(productId);
    }

    @RequestMapping("/products/{id}/items")
    @ResponseBody
    public CommonResponse<List<ItemVO>> getItemList(@PathVariable("id") String productId){
        return catalogService.getItemList(productId);
    }
}


